const std = @import("std");
const datetime = @import("datetime");

fn weekDayName(day: datetime.Weekday) []const u8 {
    return switch (day) {
        .mon => "Mon",
        .tue => "Tue",
        .wed => "Wed",
        .thu => "Thu",
        .fri => "Fir",
        .sat => "Sat",
        .sun => "Sun",
    };
}

fn monthName(month: datetime.Month) []const u8 {
    return switch (month) {
        .jan => "Jan",
        .feb => "Feb",
        .mar => "Mar",
        .apr => "Apr",
        .may => "May",
        .jun => "Jun",
        .jul => "Jul",
        .aug => "Aug",
        .sep => "Sep",
        .oct => "Oct",
        .nov => "Nov",
        .dec => "Dec",
    };
    // return @tagName(month);
}

pub const Datetime = struct {
    datetime: datetime.DateTime,

    pub fn now() Datetime {
        return .{ .datetime = datetime.DateTime.now() };
    }

    pub fn format(self: Datetime, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
        if (std.mem.eql(u8, "rfc1123", fmt)) {
            try std.fmt.format(writer, "{s}, {d:0>2} {s} {d} {rfc3339} GMT", .{
                weekDayName(self.datetime.date.weekday()),
                self.datetime.date.day,
                monthName(self.datetime.date.month),
                self.datetime.date.year,
                self.datetime.time,
            });
        } else {
            try self.datetime.format(fmt, options, writer);
        }
    }
};
